package com.example.myapplication.activity.advanced_activity;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

import com.example.myapplication.R;

public class SwitchDefaultActivity extends AppCompatActivity {

    @SuppressLint("UseSwitchCompatOrMaterialCode")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_switch_default);
        Switch switch_state = findViewById(R.id.sw_status);
        TextView tv = findViewById(R.id.tv_result);
        switch_state.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                tv.setText(tv.getText() + "打开了");
            } else {
                tv.setText(tv.getText() + "关闭了");

            }
        });
    }
}